****************************************************************************
* File-Nale: 		analyses.do
* Date:		 04/06/2020
* Author: 		Fred Batista
* Purpose: 		Main Analysis for paper
* Data used: 		lapop10irt.dta
* Data Output:	None	*/
****************************************************************************


*** More data preparation

* re-scaling construct4 and construct3 (from 0 tom100)

summarize construct4

gen const4_0100= 100*(construct4 - r(min))/(r(max) - r(min)) 

label variable const4_0100 "IRT Scale 0-100"

summarize construct3

gen const3_0100= 100*(construct3 - r(min))/(r(max) - r(min)) 

label variable const3_0100 "Alternative IRT Scale 0-100"

* pol know 100

gen polknow_0100 = polknow*100/3


*** Correlations between different scales

pwcorr polknow_0100 const4_0100 const3_0100 stdknow_0100 facknow_0100 bigfacknow_0100 [aweight=weight1500], sig


*** ANALYSES

** "model for features of the battery of items (numbprovince, lastchangeprov, roundnumber, reelection, fiveseixyears, lastelection, mercha09, tourism09)

* number of provinces

xtmelogit province wealth employed schooling urban age2 man exposure interest efficacy || country:, ml

xtmelogit province wealth employed schooling urban age2 man exposure interest efficacy numbprovince lastchangeprov roundnumber || country:, ml

* length of term

xtmelogit timeterm wealth employed schooling urban age2 man exposure interest efficacy || country:, ml

xtmelogit timeterm wealth employed schooling urban age2 man exposure interest efficacy reelection fivesixyears lastelection || country:, ml

* US president

xtmelogit uspres wealth employed schooling urban age2 man exposure interest efficacy || country:, ml

xtmelogit uspres wealth employed schooling urban age2 man exposure interest efficacy tourism09 mercha09 || country:, ml

* additive scale

xtmixed polknow_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed polknow_0100 wealth employed schooling urban age2 man exposure interest efficacy numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

* IRT scale

xtmixed const4_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed const4_0100 wealth employed schooling urban age2 man exposure interest efficacy numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

* standardized scores by country

xtmixed stdknow_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed stdknow_0100 wealth employed schooling urban age2 man exposure interest efficacy numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

* factor scores by country

xtmixed facknow_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed facknow_0100 wealth employed schooling urban age2 man exposure interest efficacy numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

* scores from factor analysis all sample

xtmixed bigfacknow_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed bigfacknow_0100 wealth employed schooling urban age2 man exposure interest efficacy numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

* alternative IRT scale (uspres diff set to 1)

xtmixed const3_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed const3_0100 wealth employed schooling urban age2 man exposure interest efficacy numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml



*** Main Models

* additive scale

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country:, ml

* IRT scale

xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country:, ml


* standardized scores by country

xtmixed stdknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed stdknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country:, ml

* factor scores by country

xtmixed facknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed facknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country:, ml

* scores from factor analysis all sample

xtmixed bigfacknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed bigfacknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country:, ml

* alternative IRT scale (uspres diff set to 1)

xtmixed const3_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed const3_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country:, ml



*** Models for Social Spending (5 missing cases)

* additive scale

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] if socspen08!=. || country:, ml

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac socspen08 [pweight=weight1500] || country:, ml

* IRT scale
xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] if socspen08!=. || country:, ml


xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac socspen08 [pweight=weight1500] || country:, ml

* standardized additive scale

xtmixed stdknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac socspen08 [pweight=weight1500] || country:, ml

* factor scores by country

xtmixed facknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac socspen08 [pweight=weight1500] || country:, ml

* factor scores all sample

xtmixed bigfacknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac socspen08 [pweight=weight1500] || country:, ml



*** assessing the influence of bridging

* model only for bridging cases

xtmixed const4_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] if bridges!=. || country:, ml

xtmixed const4_0100 wealth employed schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] if bridges!=. || country:, ml

* model only for non-bridges (ability estimates)

xtmixed const4_0100 wealth employed schooling urban age2 man exposure interest efficacy [pweight=weight1500] if bridges==.|| country:, ml

xtmixed const4_0100 wealth employed schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] if bridges==.|| country:, ml


*** Cross-level interactions

* Proportionality and education

* IRT scale

xtmixed const4_0100 wealth employed urban age2 man exposure interest efficacy schooling [pweight=weight1500] || country: schooling, ml cov(un)

xtmixed const4_0100 wealth employed urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 frac c.proportionality##c.schooling [pweight=weight1500] || country: schooling, ml cov(un)

margins, dydx(schooling) at (proportionality=(0 (2) 20)) vsquish post


matrix educ = (1.57\1.66\1.75\1.84\1.94\2.03\2.12\2.21\2.30\2.39\2.49)

matrix educlow = (0.87\1.04\1.21\1.38\1.54\1.70\1.85\1.98\2.09\2.16\2.21)

matrix educup = (2.26\2.27\2.28\2.31\2.33\2.35\2.39\2.44\2.52\2.62\2.76)

matrix prop = (0\2\4\6\8\10\12\14\16\18\20)

matrix educprop = prop, educ, educlow, educup

matrix list educprop

svmat educprop, names(l)

graph twoway (line l2 l1, lcolor(black) lpattern(solid)) (line l3 l1, lcolor(black) lpattern(shortdash)) (line l4 l1, lcolor(black) lpattern(shortdash)), ytitle("{stSans:Marginal effect of education}", size(large)) xtitle("{stSans:Proportionality}", size(large)) ylabel(0(.5)3, tl(2) labgap(2) nogrid) xlabel (0(5)20) legend(off) title({stSans: {bf:IRT Scale}}) xscale(noextend) yscale(noextend) plotregion(style(none)) graphregion(color(white)) name(propeduc)

graph export propeduc.pdf

* additive scale

xtmixed polknow_0100 wealth employed urban age2 man exposure interest efficacy schooling [pweight=weight1500] || country: schooling, ml cov(un)

xtmixed polknow_0100 wealth employed urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 frac c.proportionality##c.schooling [pweight=weight1500] || country: schooling, ml cov(un)

margins, dydx(schooling) at (proportionality=(0 (2) 20)) vsquish post


matrix educ2 = (2.11\2.11\2.11\2.11\2.10\2.10\2.10\2.09\2.09\2.09\2.09)

matrix educlow2 = (1.27\1.36\1.45\1.54\1.63\1.70\1.77\1.82\1.83\1.81\1.76)

matrix educup2 = (2.96\2.86\2.76\2.67\2.58\2.50\2.42\2.37\2.35\2.37\2.42)

matrix prop2 = (0\2\4\6\8\10\12\14\16\18\20)

matrix educprop2 = prop2, educ2, educlow2, educup2

matrix list educprop2

svmat educprop2, names(q)

graph twoway (line q2 q1, lcolor(black) lpattern(solid)) (line q3 q1, lcolor(black) lpattern(shortdash)) (line q4 q1, lcolor(black) lpattern(shortdash)), ytitle("{stSans:Marginal effect of education}", size(large)) xtitle("{stSans:Proportionality}", size(large)) ylabel(0(.5)3, tl(2) labgap(2) nogrid) xlabel (0(5)20) legend(off) title({stSans: {bf:Additive Scale}}) xscale(noextend) yscale(noextend) plotregion(style(none)) graphregion(color(white))  name(propeduc2)

graph export propeduc2.pdf


* general factor

xtmixed bigfacknow_0100 wealth employed urban age2 man exposure interest efficacy schooling [pweight=weight1500] || country: schooling, ml cov(un)

xtmixed bigfacknow_0100 wealth employed urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 frac c.proportionality##c.schooling [pweight=weight1500] || country: schooling, ml cov(un)


*standardize scores by country

xtmixed stdknow_0100 wealth employed urban age2 man exposure interest efficacy schooling [pweight=weight1500] || country: schooling, ml cov(un)

xtmixed stdknow_0100 wealth employed urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 frac c.proportionality##c.schooling [pweight=weight1500] || country: schooling, ml cov(un)

* factors by country

xtmixed facknow_0100 wealth employed urban age2 man exposure interest efficacy schooling [pweight=weight1500] || country: schooling, ml cov(un)

xtmixed facknow_0100 wealth employed urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 frac c.proportionality##c.schooling [pweight=weight1500] || country: schooling, ml cov(un)

* IRT anchoring

xtmixed const3_0100 wealth employed urban age2 man exposure interest efficacy schooling [pweight=weight1500] || country: schooling, ml cov(un)

xtmixed const3_0100 wealth employed urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 frac c.proportionality##c.schooling [pweight=weight1500] || country: schooling, ml cov(un)






*effects on internal efficacy

xtmixed efficacy wealth employed schooling urban age2 man exposure interest [pweight=weight1500] || country: , ml

xtmixed efficacy wealth employed schooling urban age2 man exposure interest gdpover1000 telecoms_tenmill freehinv09 proportionality frac [pweight=weight1500] || country: , ml


* figures of country comparisons

sort country

mean const4_0100 if country2==1

mean const4_0100 if country2==2

mean const4_0100 if country2==3

mean const4_0100 if country2==4

mean const4_0100 if country2==5

mean const4_0100 if country2==6

mean const4_0100 if country2==7

mean const4_0100 if country2==8

mean const4_0100 if country2==9

mean const4_0100 if country2==10

mean const4_0100 if country2==11

mean const4_0100 if country2==12

mean const4_0100 if country2==13

mean const4_0100 if country2==14

mean const4_0100 if country2==15

mean const4_0100 if country2==16

mean const4_0100 if country2==17

mean const4_0100 if country2==18

mean const4_0100 if country2==19

mean const4_0100 if country2==20

mean const4_0100 if country2==21

mean const4_0100 if country2==22

mean const4_0100 if country2==23

mean const4_0100 if country2==24


mean polknow_0100 if country2==1

mean polknow_0100 if country2==2

mean polknow_0100 if country2==3

mean polknow_0100 if country2==4

mean polknow_0100 if country2==5

mean polknow_0100 if country2==6

mean polknow_0100 if country2==7

mean polknow_0100 if country2==8

mean polknow_0100 if country2==9

mean polknow_0100 if country2==10

mean polknow_0100 if country2==11

mean polknow_0100 if country2==12

mean polknow_0100 if country2==13

mean polknow_0100 if country2==14

mean polknow_0100 if country2==15

mean polknow_0100 if country2==16

mean polknow_0100 if country2==17

mean polknow_0100 if country2==18

mean polknow_0100 if country2==19

mean polknow_0100 if country2==20

mean polknow_0100 if country2==21

mean polknow_0100 if country2==22

mean polknow_0100 if country2==23

mean polknow_0100 if country2==24

* generating figures

matrix irt = (54.32\52.08\56.85\52.52\50.36\55.54\53.09\53.14\53.75\57.75\57.14\54.70\56.19\57.09\51.53\53.31\56.88\53.13\54.37\52.81\52.31\52.58\50.59\55.24)

matrix lbirt = (53.13\50.93\55.69\51.57\49.30\54.41\52.06\52.03\52.97\56.85\55.96\53.55\55.13\55.97\50.71\52.24\55.62\51.98\53.32\51.74\51.33\51.61\49.63\54.12)

matrix ubirt = (55.51\53.24\58.01\53.48\51.42\56.67\54.11\54.25\54.53\58.65\58.34\55.87\57.25\58.21\52.34\54.39\58.13\54.29\55.41\53.88\53.30\53.55\51.54\56.36)


matrix add = (66.58\66.20\82.04\85.63\43.79\84.80\67.69\62.37\58.76\76.27\73.02\59.41\70.57\86.33\58.06\54.29\71.14\60.51\80.40\66.36\80.78\60.12\54.92\73.53)

matrix lbadd = (64.91\64.46\80.67\84.39\42.14\83.46\66.33\60.88\57.56\75.16\71.44\57.69\69.29\85.19\56.82\52.59\69.46\58.95\79.0\64.82\79.39\58.91\53.42\72.13)

matrix ubadd = (68.25\67.94\83.42\86.87\45.44\86.14\69.05\63.87\59.86\77.37\74.60\61.13\71.85\87.48\59.30\55.99\72.81\62.07\81.80\67.90\82.17\61.34\56.43\74.93)

matrix compare = irt, lbirt, ubirt, add, lbadd, ubadd

matrix list compare

svmat compare, names(y)

eclplot y1 y2 y3 y4, ciopts(lcolor(black) msize(vtiny)) estopts(color(black)) ytitle("{stSans:IRT Scale}", size(medlarge)) xtitle("{stSans:Additive Scale}", size(medlarge)) ylabel(50 "{stSans:50}" 52 "{stSans:52}" 54 "{stSans:54}" 56 "{stSans:56}" 58 "{stSans:58}" 60 "{stSans:60}", tl(2) labgap(2) nogrid) xlabel(40 "{stSans:40}" 50 "{stSans:50}" 60 "{stSans:60}" 70"{stSans:70}" 80 "{stSans:80}" 90 "{stSans:90}", tl(2) labgap(2)) plot((rspike y5 y6 y1, horizontal lcolor(black))(function y=42.2447208176338+0.182834592183183*x, range(40 90) lcolor(gs7) lpattern(dash))) aspect(1)  text(54.5 66.58 "{stSans:mx}", place(nw)) text(52 66.1 "{stSans:gt}", place(se)) text(56.85 82.04 "{stSans:sv}", place(sw)) text(52.7 85.5 "{stSans:hn}", place(nw)) text(50.5 43.6 "{stSans:ni}", place(nw)) text(55.54 84.9 "{stSans:cr}", place(se)) text(53.09 67.69 "{stSans:pa}", place(ne)) text(53.14 62.37 "{stSans:co}", place(se)) text(53.75 58.6 "{stSans:ec}", place(nw)) text(57.75 76.4 "{stSans:bo}", place(ne)) text(57 73.15 "{stSans:pe}", place(se)) text(54.8 59.4 "{stSans:py}", place(nw)) text(56.3 70.4 "{stSans:cl}", place(nw)) text(57.09 86.45 "{stSans:uy}", place(ne)) text(51.4 58.2 "{stSans:br}", place(se)) text(53.4 54.15 "{stSans:ve}", place(nw)) text(57 70.80 "{stSans:ar}", place(nw)) text(53.14 60.51 "{stSans:do}", place(sw)) text(54.25 80.5 "{stSans:ht}", place(se)) text(52.65 66.2 "{stSans:jm}", place(sw)) text(52.45 80.65 "{stSans:gy}", place(nw)) text(52.45 59.9 "{stSans:tt}", place(sw)) text(50.70 54.80 "{stSans:bz}", place(nw)) text(55.24 73.53 "{stSans:sr}", place(se)) title("{bf:{stSans: Estimates of Country Means}}") xscale(noextend) yscale(noextend) plotregion(style(none)) graphregion(color(white)) name(cmeans)

graph export cmeans.pdf


**********After jeep R&R:

** including unfair predictors with main predictors

* additive scale

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac  [pweight=weight1500] || country:, ml

xtmixed polknow_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

* bridged scale

xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy [pweight=weight1500] || country:, ml

xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac  [pweight=weight1500] || country:, ml

xtmixed const4_0100 wealth employed  schooling urban age2 man exposure interest efficacy gdpover1000 telecoms_tenmill freehinv09 proportionality frac numbprovince roundnumber lastelection fivesixyears mercha09 [pweight=weight1500] || country:, ml

** check correlation of education and items by country

* education (72/72 pos. and sig.)

by country: probit province schooling

by country: probit uspres schooling

by country: timeterm uspres schooling

* interest (60/72 pos. and sig.)

by country: probit province interest

by country: probit uspres interest

by country: probit timeterm interest

* efficacy (62/72 pos. and sig.)

by country: probit province efficacy

by country: probit uspres efficacy

by country: probit timeterm efficacy

*media exposure (69/72 pos. and sig.)

by country: probit province exposure

by country: probit uspres exposure

by country: probit timeterm exposure
